Configure Browser Settings from Tests

Applies to TestComplete 15.70, last modified on December 17, 2024

When performing web testing, you may need to modify the browser settings. That may be needed, for instance, to check whether the tested page is displayed correctly if the browser settings changed.

TestComplete provides special scripting objects that allow you to modify the browser settings directly from your tests. The rest of the topic describes how you can do this.

Note that the Chrome web browser has specific security settings that make it impossible to work with browser settings via scripting objects.

Accessing Internet Explorer Settings

You can use the following scripting objects to control and change Internet Explorer and Microsoft WebBrowser settings:

  • To access advanced settings, use the IESettings object.

    This object is returned by the Options.IESettings property. It contains Internet Explorer settings that are displayed on the Advanced page of Internet Explorer’s Internet Options dialog (this dialog is shown when you select Tools | Options from Internet Explorer’s main menu).

    For more information on available settings, see the IESettings object description.

  • To access security zone settings, use the IEZoneSettingsManager object.

    This object is returned by the Options.IEZoneSettings property. It lets you access security zone settings that are displayed on the Security Settings dialog of Internet Explorer. To display the dialog, select Tools | Options from Internet Explorer’s main menu, switch to the Security page of the ensuing Internet Options dialog and press Custom Level.

    The IEZoneSettingsManager object contains two methods: GetZoneSettingsById and GetZoneSettingsByUrl. GetZoneSettingsById provides access to security settings of the zone specified by the method parameter. GetZoneSettingsByUrl detects the zone that the specified URL belongs to and then provides scripting access to the settings of this zone.

    For more information on available zone settings, see the IEZoneSettings object description.

Note that Internet Explorer’s options, which you can change via the IESettings and IEZoneSettings objects, also affect WebBrowser controls. The changes you made to object properties will also be applied to WebBrowser controls.

Accessing Mozilla Firefox Settings

If you use the Mozilla Firefox browser, then to control and change its settings, you can use the special Preferences object.

This object is returned by the Preferences property of the object that corresponds to the Mozilla Firefox browser. Through this object you can access a variety of options that are shown in the Firefox browser when you enter about:config in the address bar and press Enter. For each option displayed on this page, the Preferences object has a corresponding property. The only difference is that similar properties are grouped by categories.

For example, the following code enables the "Smooth scrolling" feature from script. It is equivalent to selecting the Tools | Options | Advanced | General | Browsing | Use smooth scrolling option from the browser.

JavaScript, JScript

Sys.Browser("firefox").Preferences.general.smoothScroll=true;

Python

Sys.Browser("firefox").Preferences.general.smoothScroll=True;

VBScript

Sys.Browser("firefox").Preferences.general.smoothScroll = True

DelphiScript

Sys.Browser('firefox').Preferences.general.smoothScroll:=true;

C++Script, C#Script

Sys["Browser"]("firefox")["Preferences"]["general"]["smoothScroll"]=true;

However, the approach described above does not work for the preferences whose names contain hyphens. For example, the code above will not work for the "network.automatic-ntlm-auth.trusted-uris" preference. To work with such preferences from your tests, use setBoolPref, getBoolPref, setCharPref, getCharPrefm and similar methods. The code below demonstrates the mentioned approach:

JavaScript, JScript

Sys.Browser("firefox").Preferences.setCharPref("network.automatic-ntlm-auth.trusted-uris", "smartbear.com");

Python

Sys.Browser("firefox").Preferences.setCharPref("network.automatic-ntlm-auth.trusted-uris", "smartbear.com");

VBScript

Sys.Browser("firefox").Preferences.setCharPref "network.automatic-ntlm-auth.trusted-uris", "smartbear.com"

DelphiScript

Sys.Browser('firefox').Preferences.setCharPref('network.automatic-ntlm-auth.trusted-uris', 'smartbear.com');

C++Script, C#Script

Sys["Browser"]("firefox")["Preferences"]["setCharPref"]("network.automatic-ntlm-auth.trusted-uris", "smartbear.com");

Sys.Browser("firefox").Preferences.setCharPref("network.automatic-ntlm-auth.trusted-uris", "smartbear.com");

In JScript, C#Script and C++Script tests, you can also use the square bracket notation:

JavaScript, JScript

Sys.Browser("firefox").Preferences.network["automatic-ntlm-auth"]["trusted-uris"] = "smartbear.com";

C++Script, C#Script

Sys["Browser"]("firefox")["Preferences"]["network"]["automatic-ntlm-auth"]["trusted-uris"] = "smartbear.com";

See Also

How To
Launch Web Browsers
Testing Web Applications - Tutorial

Highlight search results